<!-- 关闭工单 -->
<template>
  <ve-modal v-model="visible" title="关闭原因" cancelText="取消" @cancel="onCancel" @confirm="formSubmit" :okLoading="okLoading">
    <ve-form ref="ve_form" :model="form">
      <!-- <ve-card type="none" fold> -->
      <ve-form-item label="关闭原因" labelPosition="top" :borderBottom="false" prop="closeReason">
        <ve-input type="textarea" v-model="form.closeReason" placeholder="请输入" :maxlength="100" />
      </ve-form-item>
      <!-- </ve-card> -->
    </ve-form>
  </ve-modal>
</template>

<script setup name="closeModal">
  import { ref, nextTick } from 'vue'
  import FilterNavbar from '@/components/FilterNavbar'
  import { closeWorkAPI } from '@/api/order/workOrder'
  import useFormFold from '@/hooks/useFormFold'
  const emits = defineEmits(['ok'])
  const initFold1 = ref(true)
  const visible = ref(false)
  const form = ref({
    id: '',
  })
  const toast = (e) => {
    uni.showToast({
      title: e,
      icon: 'none',
    })
  }
  const onCancel = () => {
    visible.value = false
  }
  const open = (id) => {
    visible.value = true
    form.value.id = id
  }
  const ve_form = ref(null)
  const okLoading = ref(false)
  const formSubmit = () => {
    var params = {
      ...form.value,
    }
    okLoading.value = true
    closeWorkAPI(params)
      .then((res) => {
        okLoading.value = false
        if (res.code == 200) {
          toast(res.message)
          emits('ok')
          visible.value = false
        } else {
          toast(res.message)
          return false
        }
      })
      .catch(() => {
        okLoading.value = false
      })
  }
  defineExpose({
    open,
  })
</script>

<style lang="scss" scoped>
  .container {
    background: #f7f8fa;
  }

  .viewports {
    display: flex;
    flex-direction: column;
    padding: 24rpx;
  }
</style>
